// router/index.js
import Vue from "vue";
import Router from "vue-router";
import SystemRoutes from "./system.js";

Vue.use(Router);

const router = new Router({
  mode: "history", // 可选，默认是hash模式，这里选择HTML5 history模式
  routes: [...SystemRoutes],
});

router.beforeEach((to, from, next) => {
  const token = sessionStorage.getItem("bike_token");
  const publicPaths = ["/login"];

  if (!publicPaths.includes(to.path)) {
    if (!token) {
      next("/login");
    } else {
      next();
    }
  } else {
    next();
  }
});

export default router;
